package com.enjoyor.soa.traffic.server.tsms.dubbo.invoke;

import org.springframework.stereotype.Component;

import com.alibaba.dubbo.config.annotation.Reference;
import com.enjoyor.soa.traffic.api.uums.dto.UserDto;
import com.enjoyor.soa.traffic.api.uums2.service.dubbo.DubboTokenService;
import com.enjoyor.soa.traffic.util.pojo.ResultPojo;

@Component
public class DubboTokenServiceInvoke {

    @Reference(timeout = 3000)
    private DubboTokenService dubboTokenService;

    /**
     * 解析用户
     * @param token
     * @param systemKey
     * @return
     */
    public UserDto parse(String token, String systemKey) {
        ResultPojo pojo = dubboTokenService.checkToken(token, systemKey);
        if (pojo.getAppCode().compareTo("0") == 0)
            return (UserDto) pojo.getResultList();
        else
            return null;
    }

    /**
     * 权限验证
     * 
     * @param token
     *            令牌
     * @param systemKey
     *            授权码
     */
    public ResultPojo check(String token, String systemKey) {
        ResultPojo pojo = dubboTokenService.checkToken(token, systemKey);
        return pojo;
    }

}
